package handler

import(
	"github.com/astaxie/beego/logs"
	"io"
	"io/ioutil"
	"net/http"
	"os"
)

var filePath="./static/view/index.html"
var loc="./static/"
func UploadHandler(w http.ResponseWriter,r *http.Request){
	if r.Method=="GET"{
		// 返回上传页面
		data,err:=ioutil.ReadFile(filePath)
		if err!=nil{
			w.Write([]byte("dawd"))
		}
		w.Write(data)

	}else if r.Method=="POST"{
		// 接收文件流
		file,head,err:=r.FormFile("file")
		if err!=nil{

		}
		defer file.Close()
		newFile,err:=os.Create(loc+head.Filename)
		if err!=nil{
			return
		}

		defer newFile.Close()
		_,err=io.Copy(newFile,file)
		if err!=nil{
			logs.Error(err)
			return
		}

	}
}
